20180211

使用 __repr__ 這個方法,

定義此方法來,告訴python如何此物件要如何表示(print出來)

[練習]

class Point3D(object):
  def __init__(self,x,y,z):
    self.x=x
    self.y=y
    self.z=z
  def __repr__(self):
    return "(%d, %d, %d)" %(self.x,self.y,self.z)

my_point=Point3D(1,2,3)
print my_point

results matching ""

    No results matching ""